

jQuery(function ($) {
    var user_info = JSON.parse(localStorage.getItem('user_info'));
    if (!user_info) {
        window.location.href = "/login/login.html";
    }
    var userId = user_info.id;
    var onoff = false;
    var pageOff=true;
    //余额查询切换
    $('.balance_query li').click(function () {
        var index = $(this).index();
        $(this).addClass("add_color").siblings().removeClass("add_color");
        $(".balance_explain").eq(index).addClass('open').siblings().removeClass("open");
    });
    //畜牧币明细
    ycbalance(0);
    function ycbalance(page) {
        var html = "";
        var param = {
            "[]": {
                "query": 2,
                "count": 10,
                "page": page,
                "UserPointBill": {
                    "user_id": userId,
                    "@order": "create_time-"
                }
            },
            "total@": "/[]/total"
        };
        send_ajax('post', '/get', param, function (data) {
            var user_info = JSON.parse(localStorage.getItem('user_info'));
            var balance = user_info.point;
            if (balance.toString().indexOf(".") != -1) {
                var integer = balance.toString().split('.')[0];
                var decimal = balance.toString().split('.')[1];
                $('.big_num').html(integer);
                $('.decimal').html(decimal);
            }else {
                $('.big_num').html(balance);
            }
            if (data.code == 200 && data["[]"] != undefined) {
                if(pageOff){
                    twbsPagination(data.total);
                    pageOff=false;
                }
                var data = data["[]"];
                for (var i = 0; i < data.length; i++) {
                    html += '\n                        <li class="item">\n                            <span>' + data[i].UserPointBill.create_time.split(".")[0] + '</span>\n                            <span>' + data[i].UserPointBill.point + '</span>\n                            <span>' + (data[i].UserPointBill.note ? data[i].UserPointBill.note : "") + '</span>\n                        </li>\n                    ';
                }
                $('.balanceRecord').html(html);
            }
        });
    };
    function twbsPagination(totalPage){
          Page({
            num:Math.ceil(totalPage/10),					//页码数
            startnum:1,				//指定页码
            elem:$('#pagination_b'),		//指定的元素
            callback:function(page){	//回调函数
                if (page != 1) {
                    onoff = true;
                }
                if (onoff) {
                    $('.balanceRecord').empty();
                    ycbalance(page - 1);
                }
            }
        });
    }
  
});